import redis
import time
import asyncio
import aiohttp

conn = redis.Redis()
order_id = '984062106857857'

url = 'https://dps.kdlapi.com/api/checkdpsvalid'

loop = asyncio.get_event_loop()
async def main(proxy):
    async with aiohttp.ClientSession() as session:
        if not proxy:
            proxy = None
        else:
            proxy = proxy.decode()
        try:
            async with session.get(
                    'http://upay.10010.com/npfwap/npfMobWap/bankcharge/index.html?version=wap&desmobile=6672070486447365',
                    proxy=proxy, timeout=5) as resp:
                    pass
        except Exception as e:
            print(e)
            print("异常代理%s" % proxy)
            conn.srem("un_proxy", proxy)


while True:
    proxys = conn.smembers('un_proxy')
    tasks = []
    for proxy in proxys:
        tasks.append(main(proxy))
    if tasks:
        loop.run_until_complete(asyncio.wait(tasks))
    time.sleep(5)
